import {Sequelize} from "sequelize";
import {isPhone} from '@test/util/ValidateUtil'
import {ParamException} from "@test/common/HandleException";

export const modelName = 'user'

export const attributes = {
    phone: {
        type: Sequelize.STRING(20),
        unique: true,
        validate: {
            check(val) {
                if (val) {
                    if (!isPhone(val)) {
                        throw new ParamException('手机号码格式不正确')
                    }
                } else {
                    throw new ParamException('电话号码不能为空')
                }
            }
        }
    },
    password: {
        type: Sequelize.STRING(64),
        validate: {
            check(val) {
                if (val) {
                    if (val.length < 6) {
                        throw new ParamException('密码不能小于6位')
                    }
                } else {
                    throw new ParamException('密码不能为空')
                }
            }
        }
    },
    nickName: Sequelize.STRING(50),
    sex: Sequelize.TINYINT
}

export const options = {
    tableName: 't_user'
}
